package com.googlecode.thriftbenchmark.rpc;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TTransport;


public class SimpleTProtocolFactory implements TProtocolFactory {
    
    private static final long serialVersionUID = 1L;
    
    private String protocolName;
    
    public SimpleTProtocolFactory(String protocolName) {
        this.protocolName = protocolName;
    }
    
    @Override
    public TProtocol getProtocol(TTransport trans) {
        
        if (protocolName.equals("binary")) {
            return new TBinaryProtocol(trans);
        } else if (protocolName.equals("compact")) {
            return new TCompactProtocol(trans);
        } else {
            
            throw new IllegalArgumentException("Invalid protocol name: " + protocolName);
        }
    }
    
}
